Skip to content

feat: phones get a board framed for portrait and on-screen keys, for 0.5.2 - #83

Merged
dmccoystephenson merged 1 commit into
mainfrom
feat/touch-portrait
Nov 21, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
feat/touch-portrait

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

Two things a phone needs are added to grid3d, and the version is bumped to 0.5.2.

A board framed for a phone held upright. fitCamera used the desktop's framing at every aspect, so on a phone held upright the 3D board sat low and looked small (and a large board, such as Apex's 29 x 29, ran off both sides). A portrait window (aspect below 1) is now framed for its shape: the camera looks down more steeply (70 degrees rather than about 55), the board fills the window's width (2% margins) and stands in the middle of the space below a HUD. Landscape and square windows keep 0.5.1's framing exactly, so the golden image is unchanged; between an aspect of 0.8 and 1 the two framings blend, so a resize across square doesn't make the board jump.

fitCamera, GridBoard.camera and GridBoard.scene take top and bottom, the fractions of the window's height kept clear of the board (a HUD, a bar of touch keys), in any window shape. Both views take them in pixels with view.setInsets(top=..., bottom=...); picking, cellScreenPosition and the web view's camera (a new VIEW is sent at once) follow.

On-screen keys for touch screens. TouchKeys (grid3d/touchkeys.py) lays out a bar of labelled buttons along the bottom of the screen, each at least 44 CSS pixels each way, in rows of equal buttons (up to three rows on a portrait screen, one on a landscape one). When the keys don't all fit, the last button is More (Back on the last page), which pages through the rest, so the bar never grows over the board. A tap (keys.press(position, width, height, pygame, scale)) posts the same KEYDOWN and KEYUP the keyboard would (marked touchKey=True), so a game's own key handlers do the work and the two views can't drift: parity by construction. The 2D view draws the bar with Graphik (keys.draw(graphik, ...)), the 3D view adds keys.overlay(...) (panels and labels) to its HUD, both from one layout() and one hit test. Sizes are worked out in CSS pixels; scale is a surface's CSS pixels per pixel, and keys.below(width, height, pageWidth, pageHeight) gives the band a 2D game adds under its board and the canvas's scale once the browser fits it to the page.

The page template's Graphik3D.touch() and grid3d.web.touchScreen() say whether the page is on a touch screen: a coarse pointer, or a touch already seen (a laptop's touch screen). ?touch=1 or ?touch=0 in the address overrides it for testing, and GRAPHIK_TOUCH=1 does outside a browser.

Measurements

The board's on-screen bounding box (frame included) as a share of a 390 x 844 phone screen in 3D, now and with 0.5.1's camera, read from what each game sent the page's relay (screenshots in /root/scratch/shots/2026-11-20-touch-portrait/):

game 0.5.1 0.5.2
Ophidian (5 x 5, HUD above, keys below) 0.328 (374 x 289 px at y 303) 0.367 (367 x 330 px at y 261)
Apex (29 x 29, keys below) ran 15 px off both sides 0.366, the whole board (373 x 323 px at y 175)
Tic-Tak-Toe (3 x 3, no keys) 0.275 0.346

A board can't grow past the phone's width, so the gain in a portrait window comes from standing the board taller (the steeper camera), using the full width with 2% margins and centring it in the room left by the HUD and the keys.

Landscape and desktop windows: unchanged (checked to 1e-3 against 0.5.1's camera in each game's end-to-end run).

Tests

  • test_grid3d_touch.py (new): the desktop formula is kept for every landscape and square window; the whole board stays on screen at 390x844, 844x390, 800x600, 1280x800, 900x700, 430x932 and 600x800 for seven board shapes; a portrait phone fills its width, centres the board and shows it bigger than 0.5.1 did; reserved space at the top and bottom is kept clear at every aspect; nearly square windows blend without a jump; a view's insets reach its camera, picking and the web view's VIEW; the keys' rows, sizes (44 px), paging with More and Back, key events (pygame's names), the 2D layout being the 3D layout scaled, below() on portrait and landscape phones, the 2D bar drawn with Graphik and the 3D bar as panels and labels with the same hit test; touchScreen() in a browser, with an older template and outside one.
  • The suite: 415 passed, the golden image included (with Strata 0.8.0).

Each game's adoption PR runs the keys end to end in a browser at 390 x 844 with touch, in 3D and in 2D.

drafted by Claude on behalf of Daniel Stephenson

🤖 Generated with Claude Code

…0.5.2

fitCamera frames a portrait window for its shape: the camera looks down
more steeply (70 degrees), the board fills the window's width and stands
in the middle of the space below a HUD, and a large board no longer runs
off the sides. Landscape and square windows keep 0.5.1's framing exactly
(the golden image is unchanged); between an aspect of 0.8 and 1 the two
blend. fitCamera, GridBoard.camera and GridBoard.scene take `top` and
`bottom`, the fractions of the window kept clear of the board, and both
views take them in pixels with setInsets(); picking and the web view's
camera follow.

TouchKeys (grid3d/touchkeys.py) lays out a bar of labelled buttons along
the bottom of the screen, at least 44 CSS pixels each way, paging with
More when the keys don't fit. A tap posts the KEYDOWN and KEYUP the
keyboard would, so a game's own key handling does the work; the 2D view
draws the bar with Graphik and the 3D view as screen panels and labels,
from one layout and one hit test. below() sizes the band a 2D game adds
under its board. The page template's Graphik3D.touch() and
grid3d.web.touchScreen() say whether the page is on a touch screen
(?touch=1 or ?touch=0 for testing).

The version is 0.5.2; the README describes both.

drafted by Claude on behalf of Daniel Stephenson

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
@dmccoystephenson
dmccoystephenson merged commit 510b86d into main Nov 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant